<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Agent_model extends CI_Model {
	
	function __contruct() {
		parent::__construct();
	}
	
	public function doQuery($params) {
		$type = $params['type'];
		$columns = $params['columns'];
		$table = $params['table'];
		$where = $params['where'];
		$orderBy = $params['orderBy'];
		$isCached = $params['isCached'];
		$cacheName = $params['cacheName'];
		
		switch ($type) {
			case 'select':
				$res = $this->select($columns,$where,$orderBy,$cacheName);
			break;
			case 'insert':
			
			break;
			case 'update':
			
			break;
			case 'delete':
			
			break;
			default:
			
		}
		
		$this->db->query();
		
	}
	
	private function select($columns,$table,$where = array(),$orderBy = array(),$cacheName) {
		//columns
		if(is_array($columns)) {
			$columns2 = '';
			foreach($columns as $column) {
				$columns2 .= $column.",";
			}
			$columns = substr($columns2, 0, -1);;
		} else {
			$columns = '*';
		}
		
		//where clause
		if(!empty($where)) {
			$conditions = 'WHERE TRUE and ';
			foreach ($where as $condition) {
				$conditions.= "$condition";
			}
		} else {
			$where = null;
		}
		
		//order by clause
		if(!empty($orderBy)) {
			
		}
		$SQL = "SELECT $columns FROM $table $where $orderBy";
	}
	
	private function insert() {
		
	}
	
	private function update() {
		
	}
	
	private function delete() {
		
	}
	
	
}
